package cascade.controller.templates.commands
{
	import flight.commands.AsyncCommand;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.Fault;

	public class CommandLoadTemplates extends AsyncCommand
	{
		
		public override function execute():*
		{
			Cascade.busy.addBusy(this);
			
			Cascade.service.TemplateService.loadTemplates(result, fault);
		}
		
		protected function result(templates:Array):void {
			
			Cascade.model.templates = new ArrayCollection(templates);
			
			Cascade.busy.removeBusy(this);
			
			dispatchExecutionComplete();
		}
		
		protected function fault(info:Object):void
		{
			trace(info.description || info.faultString);
			Cascade.busy.removeBusy(this);
		}
	}
}